using UnityEngine;
using System.Collections;

public class CharacterMovement_City : DrawableGameObject 
{
	
	public Texture2D[] runningTextures;
	public Texture2D[] flyingTextures;
	private float speed = 0.1f;
	
	GameObject[] BGs;
	
	public bool grounded = false;
		
	public override void Start () 
	{
		base.Start();
		base.SetAnimations(flyingTextures, runningTextures, null, null);
	}
	
	void Update () 
	{
		Move();
		RunAnimations();
		
		BGs = GameObject.FindGameObjectsWithTag("Background");
		
		foreach (GameObject bg in BGs) 
		{
			bg.GetComponent<Parallax>().SetParallax("Normal");
		}
	}
	
	public void Move()
	{
		transform.Translate(speed,0,0);
		
		if(Input.GetKey(KeyCode.Space))
		{
			gameObject.rigidbody.AddForce(0,20,0);
			grounded = false;
		}
	}
	
	public void RunAnimations()
	{
		base.gameAnimation.CalculateFps(15);
		
		if(!grounded)
		{
			base.RunAnimation("Stand", "Loop");
		}
		else
		{
			base.RunAnimation("Walk", "Loop");
		}
	}
	
	public void OnCollisionStay(Collision other)
	{
		if(other.gameObject.tag == "Ground")
		{
			grounded = true;
		}
	}
}
